package com.zara.store.server;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;

import com.zara.store.common.ProductVO;


@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("Product")
//TODO: ver si pasamos a ValueObject
public class Product {

	private int id;
	private String barcode;
	private String name;
	private String description;
	private String section;
	private String line;
	private String color;
	private String origin;
	private BigDecimal unitPrice;
	private BigDecimal salePrice;
	private BigDecimal stock;
	//punto pedido
	private BigDecimal orderStock;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId(){
		return id;
	}

	public void setId(int newVal){
		id = newVal;
	}

	@Column
	public String getBarcode(){
		return barcode;
	}

	public void setBarcode(String newVal){
		barcode = newVal;
	}

	@Column
	public String getDescription(){
		return description;
	}

	public void setDescription(String newVal){
		description = newVal;
	}

	@Column
	public String getSection(){
		return section;
	}

	public void setSection(String newVal){
		section = newVal;
	}

	@Column
	public String getLine(){
		return line;
	}

	public void setLine(String newVal){
		line = newVal;
	}

	@Column
	public String getColor(){
		return color;
	}

	public void setColor(String newVal){
		color = newVal;
	}

	@Column
	public String getOrigin(){
		return origin;
	}

	public void setOrigin(String newVal){
		origin = newVal;
	}

	@Column
	public BigDecimal getUnitPrice(){
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal newVal){
		unitPrice = newVal;
	}

	@Column
	public BigDecimal getSalePrice(){
		return salePrice;
	}

	public void setSalePrice(BigDecimal newVal){
		salePrice = newVal;
	}

	@Column
	public BigDecimal getStock(){
		return stock;
	}

	public void setStock(BigDecimal newVal){
		stock = newVal;
	}

	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column
	public BigDecimal getOrderStock() {
		return orderStock;
	}

	public void setOrderStock(BigDecimal orderStock) {
		this.orderStock = orderStock;
	}
	
	public String toString() {
		return getBarcode()+", "+getName();
	}

	public Product() {
		// hib;
	}

	public Product(ProductVO productVO) {
		id = productVO.getId();
		barcode = productVO.getBarcode();
		name = productVO.getName();
		description = productVO.getDescription();
		section = productVO.getSection();
		line = productVO.getLine();
		color = productVO.getColor();
		origin = productVO.getOrigin();
		unitPrice = productVO.getUnitPrice();
		salePrice =productVO.getSalePrice();
		stock = productVO.getStock();
		orderStock = productVO.getOrderStock();
	}
	
	@Transient
	public ProductVO toVO() {
		ProductVO p = new ProductVO();
		p.setId(id);
		p.setBarcode(barcode);
		p.setName(name);
		p.setDescription(description);
		p.setSection(section);
		p.setLine(line);
		p.setColor(color);
		p.setOrigin(origin);
		p.setUnitPrice(unitPrice);
		p.setSalePrice(salePrice);
		p.setStock(stock);
		p.setOrderStock(orderStock);
		return p;
	}

}
